package com.ljj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ljj.pojo.Exam;
import com.ljj.mapper.ExamMapper;
import com.ljj.service.ExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LJJ
 * @since 2020-07-11
 */
@Service
public class ExamServiceImpl  implements ExamService {

    @Autowired
    ExamMapper examMapper;

    public List<Exam> queryExam(){
        List<Exam> exams = examMapper.selectList(null);
        return exams;
    }

//    更加单个id查找考试
    @Override
    public Exam queryOneExam(int id) {
        return examMapper.selectById(id);
    }

    //    根据多个id查找考试
    @Override
    public List<Exam> queryEByids(List<Integer> ids) {
        return examMapper.selectBatchIds(ids);
    }



    //    查询所有考试,分页
    @Override
    public PageInfo<Exam> queryExamBySuPage(String subjects, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<Exam> wrapper = new QueryWrapper<>();
        wrapper.like("subjects", subjects);
        List<Exam> exams = examMapper.selectList(wrapper);
        PageInfo<Exam> examPageInfo = new PageInfo<>(exams);
        return examPageInfo;
    }

    //    根据多个id查询考试,分页
    @Override
    public PageInfo<Exam> queryEByCPage(List<Integer> list,  Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Exam> exams = examMapper.selectBatchIds(list);
        PageInfo<Exam> examPageInfo = new PageInfo<>(exams);
        return examPageInfo;
    }


//    添加考试
    @Override
    public int insertExam(Exam exam) {
        return examMapper.insert(exam);
    }

//    修改考试
    @Override
    public int updateExam(Exam exam) {
        return examMapper.updateById(exam);
    }

//    删除考试
    @Override
    public int deleteExam(int id) {
        return examMapper.deleteById(id);
    }

    //    根据科目查询
    public PageInfo<Exam> queryExamPage(Integer pageNum,Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Exam> exams = examMapper.selectList(null);
        PageInfo<Exam> pageInfo=new PageInfo<>(exams);
        return pageInfo;
    }




}
